import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
class User{
    public String username;
    public String password;
}
@WebServlet("/postJson")
public class PostJson extends HttpServlet {
    private ObjectMapper objectMapper=new ObjectMapper();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        User user=objectMapper.readValue(req.getInputStream(),User.class);
        //规定字符格式
        resp.setContentType("text/html;charset=utf8");
        resp.getWriter().write("姓名："+user.username+" 密码："+user.password);
    }
}
